package com.hhh.petadopt.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hhh.petadopt.pojo.Lost;
import com.hhh.petadopt.pojo.LostMessage;
import com.hhh.petadopt.service.LostAndFoundService;
import com.hhh.petadopt.utils.JsonUtils;

/**
 * 失物招领内容展示
 * @author 杜镇声声
 *
 */
@Controller
public class LostController {
	
	@Autowired
	private LostAndFoundService lostAndFoundService;
	
	//展示失物招领列表
	@RequestMapping(value="/lost/LostLost")
	public String showLost(Model model) {
		//执行查询
		List<Lost> lostList = lostAndFoundService.selectLostAndfound();
		//将数据保存到域中
		model.addAttribute("lostList", lostList);
		return "lostAndFound";
	}
	
	//查询失物的详情
	@RequestMapping(value="/lost/lostInfo")
	public String findLostInfo(Integer id,Model model) {
		//执行查询
		Lost lostInfo = lostAndFoundService.selectLostById(id);
		//将数据保存到域中
		model.addAttribute("lostInfo", lostInfo);
		return "lostInfo";
	}
	
	//显示留言列表
	@RequestMapping(value="/lost/Lostmeaasge")
	@ResponseBody
	public List<LostMessage> showmessage(String lid) {
		//执行
		List<LostMessage> meassagess = lostAndFoundService.selectMessages(lid);
		
		return meassagess;
	}
	//插入留言
	/*@RequestMapping(value="/lost/losmessage")
	public String savemessage(Integer lid,String founder,String pname,String lmessage) {
		LostMessage lmessage1 = new LostMessage();
		lmessage1.setLid(lid);
		lmessage1.setFounder(founder);
		lmessage1.setPname(pname);
		lmessage1.setLmessage(lmessage);
		lostAndFoundService.inertMessage(lmessage1);
		return "forward:/lost/lostInfo?id="+lid;
		
	}*/
	
	//插入留言
		@RequestMapping(value="/lost/losmessage")
		@ResponseBody
		public String savemessage(LostMessage lmessage1) {
			
			lostAndFoundService.inertMessage(lmessage1);
			String str = "成功!";
			return JsonUtils.objectToJson(str);
			
		}

}
